import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class ShutdownListener implements ApplicationListener<ContextClosedEvent> {
    @Value("${shutdown-waittime:5000}")
    private Integer waitTime;

    @Override
    public void onApplicationEvent(ContextClosedEvent event) {
        try {
            log.info(">>>>>>>>>>>>........sleep{}毫秒，等待其他服务刷新nacos缓存", waitTime);
            Thread.sleep(waitTime);
        } catch (Exception e) {
            log.error(">>>>>>>>>>>>等待停服被中断", e);
        }
    }
}